// @ 516
// _(:з」∠)_

define([ ], function() {
    'use strict';

    let rightMainPanel = {
        init: function( param ) {
            let main = document.querySelector("main.main"),
                rightMain = main.querySelector(".rightMain"),
                rightMainView = `<div class="rightMain">
                                                <div class="rightMain_cont"></div>
                                                <ul class="rightMain_nav"></ul>
                                            </div>`;
            if ( rightMain ) rightMain.remove();
            main.insertAdjacentHTML("beforeEnd", rightMainView);

            // 初始化不同类型模块
            let moduleList = [];
            switch( param.type ) {
                case "area":
                    moduleList = [ 0, 1, 3, 4, 5 ];
                    break;
                case "point":
                    moduleList = [ 1, 2, 3, 4, 5 ];
                    break;
            }

            // 获取右侧导航信息
            RST.basic( Path + "/data/basic/rightNav.json", "", function( result ) {
                
                if ( result.data.disaster.length < 1 ) return false;

                rightMain = main.querySelector(".rightMain");

                let navList = main.querySelector(".rightMain_nav"),
                    contList = main.querySelector(".rightMain_cont"),
                    navItem = ``, contItem = ``, valueArry = [];

                // 循环信息
                for ( let x = 0; x < moduleList.length; x++ ) {
                    let data = result.data.disaster[ moduleList[x] ],
                        navItemIcon = ``;

                    navItemIcon = `<i class="fa ${ data.awesome }" aria-hidden="true"></i>`;
                    if ( data.image != "" ) { navItemIcon = `<img src="${ Path + data.image }" />`; }
                    if ( data.name != "" ) { navItemIcon = `${ data.title }`; }

                    navItem += `<li class="nav_item" title="${ data.title }"> ${ navItemIcon } </li>`;

                    contItem += `<div class="cont_item ${ data.value }">
                                            <div class="item_head">
                                                <h>${ data.name }</h>
                                            </div>
                                            <div class="item_cont"></div>
                                        </div>`;
                    valueArry.push( data.value );
                }
                navList.insertAdjacentHTML("beforeEnd", navItem);
                contList.insertAdjacentHTML("beforeEnd", contItem);

                // 事件处理
                let moduleNav = navList.querySelectorAll(".nav_item"),
                    moduleCont = contList.querySelectorAll(".cont_item");

                for ( let x = 0; x < moduleNav.length; x++ ) {
                    moduleNav[x].addEventListener( "click", function( e ) {
                        if ( moduleNav[x].hasClass("select") ) {
                            moduleNav[x].removeAllClass("select");

                            if ( contList.clientWidth > 10 ) contList.removeClass("select");
                        } else {
                            moduleNav[x].removeAllClass("select");
                            moduleNav[x].addClass("select");
                            
                            contList.scrollTop = moduleCont[x].offsetTop;
                            if ( contList.clientWidth <= 10 ) contList.addClass("select");
                        }
                    }, false);
                }
                moduleNav[0].click();

                // 引入单项内容
                require([ "./script/views/rightView/disDetilas" ], function( detila ) {
                    for  ( let x = 0; x < valueArry.length; x++ ) {
                        let insetElmt = contList.querySelector( "."+valueArry[x]+" .item_cont");
                        detila[ valueArry[x] ]({
                            type: param.type,
                            eventId: param.eventId,
                            disType: param.disType,
                            areaCode: param.areaCode,
                            latlng: param.latlng,
                            insetElmt: insetElmt,
                            className: valueArry[x]
                        });
                    }
                });
            });
        }
    }
   
    window.rightMainPanel = rightMainPanel;
    
    return rightMainPanel;
});